<template>
  <view class="u-page">
    <u-sticky>
      <view class="filter-box">
        <u-search :show-action="true" actionText="搜索" :animation="true"> </u-search>
      </view>
    </u-sticky>

    <u-list @scrolltolower="scrolltolower">
      <u-list-item v-for="(item, index) in datalist" :key="index">
        <MsgItem @onclickItem="goToChat"></MsgItem>
      </u-list-item>
    </u-list>
    <u-loadmore :status="status" />
  </view>
</template>

<script>
var Apis = {
  getWorkList: '/Open/Work/GetWorkList',
  AddWork: '/Open/Work/AddWork',
}
import { mapGetters, mapActions } from 'vuex'
import Vue from 'vue'
import MsgItem from './msgItem.vue'
const log = console.log.bind(console)

export default {
  components: { MsgItem },

  data() {
    return {
      status: '向上滑动加载更多内容',
      avatarUrl: '',
      phone: '',
      title: '海量职位，工作无忧！',
      guestContent: '',
      workerContent: '',
      datalist: [{}, {}, {}],
      optLis: [{ label: '区域' }, { label: '福利' }, { label: '薪资' }, { label: '更多' }],
    }
  },

  onLoad() {},
  computed: {
    ...mapGetters(['gid', 'token', 'roles', 'wid']),
  },
  mounted() {
    // this.getList()
  },

  methods: {
    ...mapActions({
      getToken: 'user/getToken',
      setName: 'user/setName',
      setWid: 'user/setWid',
    }),

    testting() {
      uni.navigateToMiniProgram({
        appId: 'wx7ee7b5bd64840986',
        path: 'pages/login/login',
        extraData: {
          data1: 'test',
        },
        success(res) {
          // 打开成功
        },
      })
    },

    scrolltolower(e) {
      log('scrolltolower', e)
    },
    testAddWork() {
      let data = {
        Gid: this.$u.guid(),
        CreateTime: uni.$u.date(new Date(), 'yyyy-mm-dd hh:MM:ss'),
        Location: '天心区百什街道',
        WorkType: '',
        CountOfNeed: uni.$u.random(10, 20),
        MinAge: 18,
        MaxAge: 30,
        MinPay: 3000,
        MaxPay: 6000,
        Notes: '',
        WorkName: '车工',
        Addr: '',
        EmployName: '爱彼此服装厂',
        AwardTips: '',
        Award: 100,
        Phone: '1111111',
        SocialSecurity: '',
        EmployId: '111',
      }
      this.$http.post(Apis.AddWork, data)
      log(data)
    },

    testWorkerAuth() {
      if (this.roles.indexOf('worker') > -1) {
        console.log('已经有worker权限')
      } else {
        console.log('获取worker权限')
        this.$route({
          url: '/pages/authguide/index',
          params: {
            role: 'worker',
          },
          type: 'navigateTo',
        })
      }
    },
    goToChat() {
      this.$route({
        url: '/subPackages/message/chat/index',
        params: {
          workid: '0',
        },
        type: 'navigateTo',
      })
    },
    getList(p = 1, l = 10) {
      this.$http
        .get(Apis.getWorkList, {
          params: { page: p, limit: l },
        })
        .then((res) => {
          this.datalist = res.List
        })
        .catch((err) => {
          this.guestContent = '请求失败没有内容返回'
        })
    },
  },
}
</script>

<style lang="scss">
.filter-box {
  padding: 16upx 0;
  background: #ffffff;
  border-bottom: 1px #dddddd solid;
}
</style>
